unlink thread later
authorTom Tromey <tromey@redhat.com>
Thu, 4 Jul 2013 04:00:43 +0000 (22:00 -0600)
committerTom Tromey <tromey@redhat.com>
Thu, 4 Jul 2013 04:00:43 +0000 (22:00 -0600)
unlink thread from global list later
also remove some unnecessary destruction code

src/thread.c

index 361968489c66450eff90e779d83b2f332b588388..8a81a1021a63851bb5010a45c8867e53d3daa6a6 100644 (file)
@@ -645,17 +645,6 @@ run_thread (void *state)
 
   update_processes_for_thread_death (Fcurrent_thread ());
 
-  /* Unlink this thread from the list of all threads.  */
-  for (iter = &all_threads; *iter != self; iter = &(*iter)->next_thread)
-    ;
-  *iter = (*iter)->next_thread;
-
-  self->m_last_thing_searched = Qnil;
-  self->m_saved_last_thing_searched = Qnil;
-  self->name = Qnil;
-  self->function = Qnil;
-  self->error_symbol = Qnil;
-  self->error_data = Qnil;
   xfree (self->m_specpdl);
   self->m_specpdl = NULL;
   self->m_specpdl_ptr = NULL;
@@ -664,6 +653,14 @@ run_thread (void *state)
   current_thread = NULL;
   sys_cond_broadcast (&self->thread_condvar);
 
+  /* Unlink this thread from the list of all threads.  Note that we
+     have to do this very late, after broadcasting our death.
+     Otherwise the GC may decide to reap the thread_state object,
+     leading to crashes.  */
+  for (iter = &all_threads; *iter != self; iter = &(*iter)->next_thread)
+    ;
+  *iter = (*iter)->next_thread;
+
   release_global_lock ();
 
   return NULL;